/*反馈建议
彭济
9-23*/
import Sequelize from 'sequelize'
import sequelize from './../../database'

const FeedBack = sequelize.define('sys_feedback',{
	id:{
        type: Sequelize.UUIDV4,
        defaultValue: Sequelize.UUIDV4,
        unique: true,
        allowNull: false,
        primaryKey:true
    },
    content:{
    	type: Sequelize.STRING,
        allowNull:false
    },
    feedback_time:{
    	type: Sequelize.DATE,
        allowNull:false
    },
    nickname:{
    	type: Sequelize.STRING,
        allowNull:true
    },
    contact:{
    	type: Sequelize.STRING,
        allowNull:false
    },
    is_view:{
    	type: Sequelize.INTEGER,
        allowNull:false,
        defaultValue:0,
    },
},{
	tableName:'sys_feedback'
});

class FeedBackModel{
	insertFeedback(record){
		return FeedBack.create(record);
	}
	delFeedback(id){
		return FeedBack.destroy({
			where:{
				id:id
			}
		});
	}
	//分页
	feedbackListpage(record){
		return FeedBack.findAndCount({
			limit:record.page_size,
            offset: record.page_size * (record.page_no -1)
		});
	}
	feedbackFindAll(){
		return FeedBack.findAll();
	}
	feedbackFindById(id){
		return FeedBack.findById(id);
	}
	updateFeedBack(record){
		return FeedBack.update(record,{
			where:{
				id:record.id
			},
			fields:['is_view']
		});
	}
}
module.exports = new FeedBackModel();